<?php

namespace app\api\model;

use app\admin\model\Admin;
use think\Model;

class CustomerReconciliation extends Model
{
    protected $autoWriteTimestamp = true;
    protected $type = ['images' => 'json', 'business_time' => 'timestamp'];
    // 定义全局的查询范围
    protected function base($query)
    {
        $c = Admin::find(\app\http\GetUid::getUId());
        // 门店负责人可查看自己门店的所有信息
        if ($c->level == 2) {
            $maker = Admin::where('store', $c->store)->where('level', 3)->column('id');
        } elseif ($c->level == 1) {
            $maker = Admin::column('id');
        } else {
            $maker = $c->id;
        }
        $query->whereIn('maker', $maker);
    }

    public function setAccount()
    {
        return $this->belongsTo(SetAccount::class, 'set_account_id');
    }

    public function customer()
    {
        return $this->belongsTo(UserModel::class, 'customer_id');
    }

    public function accountType()
    {
        return $this->belongsTo(AccountType::class, 'account_type_id');
    }
}
